package com.ycy;

import java.util.Random;

public class Utils {

  /**
   * 获取大小为size 的数组
   */
  public static int[] RandomArr(int size) {
    int[] arr = new int[size];
    Random random = new Random();
    for (int i = 0; i < size; i++) {
      arr[i] = random.nextInt(100);
    }
    return arr;
  }

  public static boolean checkSort(int[] arr, boolean asc) {
    if (arr.length < 2) {
      return true;
    }
    for (int i = 1; i < arr.length; i++) {
      int cur = arr[i];
      int pre = arr[i - 1];
      if (compare(cur,pre, asc)) {
        continue;
      }else {
        return false;
      }
    }
    return true;
  }

  private static boolean compare(int cur, int pre, boolean asc) {
    return asc ? pre <= cur : pre >= cur;
  }


}
